<%@page import="rjeutsky.ControllerWrapper"%>
<%@page import="rjeutsky.models.User"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Выписанные издания пользователя</title>
</head>
<%
	if (session.getAttribute("currentUser") == null) {
		response.sendRedirect("Login.jsp");
	}

	boolean isAdmin = rjeutsky.ControllerWrapper
			.getApplicationController().checkIsAdmin(
					(User) session.getAttribute("currentUser"));
	if (!isAdmin) {
		response.sendError(403);
	}

	try {
		Long id = Long.parseLong(request.getParameter("id"));
		User selectedUser = ControllerWrapper
				.getApplicationController().getUser(id);
		if (selectedUser == null) {
			response.sendError(404);
		} else {
			pageContext.setAttribute("items",
					ControllerWrapper.getApplicationController()
							.getUserPublications(selectedUser));
		}
	} catch (NumberFormatException ex) {
		response.sendError(404);
	}
%>
<body>
	<table>
		<tr>
			<td><jsp:include page="Menu.jsp" /></td>
			<td><c:if test="${items.size() > 0}">
					<table>
						<tr>
							<th>Название</th>
							<th>Цена</th>
						</tr>
						<c:forEach var="publication" items="${items }">
							<tr>
								<td>${publication.name}</td>
								<td>${publication.price }</td>
							</tr>
						</c:forEach>
					</table>
				</c:if> <c:if test="${items.size() == 0}">
					<span>Пользователь не подписан ни на одно Издание</span>
				</c:if> <a href="${pageContext.request.contextPath}/Users.jsp">Назад</a>
			<td>
		</tr>
	</table>
</body>
</html>